﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace PRE.Salary
{
    public partial class FrmXembangluong : DevExpress.XtraEditors.XtraForm
    {
        #region Variable
        DAL.EntitiesDAL.NhanvienDAL _dal = new DAL.EntitiesDAL.NhanvienDAL();
        BLL.EntitiesBLL.NhanvienBLL _bll = new BLL.EntitiesBLL.NhanvienBLL();

        DataTable _dtb = new DataTable();
        #endregion

        #region Inits
        public FrmXembangluong()
        {
            InitializeComponent();
        }
        #endregion

        #region Thoát
        private void bto_Thoát_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        #endregion

        #region Xem
        private void bto_Tim_Click(object sender, EventArgs e)
        {
            string ma = Convert.ToString(txt_manhanvien.Text);
            DataTable _dtbtim = _dal.Select_Nhanvien_Luong(ma);
            try
            {
                ResetText();
                ClearData();
                if (_dtbtim != null)
                {
                    txt_hoten.DataBindings.Add("Text", _dtbtim, ".HOTEN");
                    txt_gioitinh.DataBindings.Add("Text", _dtbtim, ".GIOITINH");
                    txt_ngaysinh.DataBindings.Add("Text", _dtbtim, ".NGAYSINH");
                    txt_cmnd.DataBindings.Add("Text", _dtbtim, ".CMND");                   
                    txt_thanhtien.DataBindings.Add("Text", _dtbtim, ".THANHTIEN");                   
                    txt_mucluong.DataBindings.Add("Text", _dtbtim, ".MUCLUONG");
                    txt_hesoluong.DataBindings.Add("Text", _dtbtim, ".HESOLUONG");
                    txt_hesophucap.DataBindings.Add("Text", _dtbtim, ".HESOPHUCAP");
                    txt_tienphucap.DataBindings.Add("Text", _dtbtim, ".TIENPHUCAP");
                    txt_tenphongban.DataBindings.Add("Text", _dtbtim, ".TENPHONGBAN");
                    txt_tenchucvu.DataBindings.Add("Text", _dtbtim, ".TENCHUCVU");
                    txt_tongtien.DataBindings.Add("Text", _dtbtim, ".TONGTIEN");                   
                    txt_thamnien.DataBindings.Add("Text", _dtbtim, ".THAMNIEN");
                }

            }
            catch (Exception ex)
            {
                XtraMessageBox.Show("Không tìm thấy nhân viên này!", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        #endregion       

        #region From load
        private void FrmXembangluong_Load(object sender, EventArgs e)
        {           
            txt_cmnd.Properties.ReadOnly = true;           
            txt_gioitinh.Properties.ReadOnly = true;
            txt_hesoluong.Properties.ReadOnly = true;
            txt_hesophucap.Properties.ReadOnly = true;           
            txt_hoten.Properties.ReadOnly = true;
            txt_mucluong.Properties.ReadOnly = true;          
            txt_ngaysinh.Properties.ReadOnly = true;          
            txt_tenchucvu.Properties.ReadOnly = true;
            txt_tenphongban.Properties.ReadOnly = true;
            txt_thamnien.Properties.ReadOnly = true;
            txt_tienphucap.Properties.ReadOnly = true;
            txt_tongtien.Properties.ReadOnly = true;
            txt_thanhtien.Properties.ReadOnly = true;
        }
        #endregion

        protected void ResetText()
        {            
            txt_cmnd.ResetText();          
            txt_gioitinh.ResetText();
            txt_hesoluong.ResetText();
            txt_hesophucap.ResetText();         
            txt_hoten.ResetText();
            txt_mucluong.ResetText();         
            txt_ngaysinh.ResetText();          
            txt_tenchucvu.ResetText();
            txt_tenphongban.ResetText();
            txt_thamnien.ResetText();
            txt_tienphucap.ResetText();
            txt_thanhtien.ResetText();
            txt_tongtien.ResetText();
        }

        protected void ClearData()
        {
            txt_hoten.DataBindings.Clear();
            txt_gioitinh.DataBindings.Clear();
            txt_ngaysinh.DataBindings.Clear();
            txt_cmnd.DataBindings.Clear();           
            txt_mucluong.DataBindings.Clear();
            txt_hesoluong.DataBindings.Clear();
            txt_hesophucap.DataBindings.Clear();          
            txt_tenphongban.DataBindings.Clear();
            txt_tenchucvu.DataBindings.Clear();           
            txt_tienphucap.DataBindings.Clear();
            txt_tongtien.DataBindings.Clear();
            txt_thanhtien.DataBindings.Clear();
            txt_thamnien.DataBindings.Clear();
        }

        #region In dữ liệu
        private void bto_In_Click(object sender, EventArgs e)
        {
            var _tongtien = txt_tongtien.Text;
            int _tongtienbangchu=0;
            string _NgayKy = "TP.Cần Thơ, ngày " + DateTime.Now.Day + " tháng " + DateTime.Now.Month + " năm " + DateTime.Now.Year;
            _tongtienbangchu += Convert.ToInt32((txt_tongtien.Text).ToString());
            string _ketquabangchu = UTL.Currency.ToString(_tongtienbangchu);

            Reports.FrmReportView frm = new Reports.FrmReportView();
            frm._load_XtraBangluong(_dtb, txt_manhanvien.Text, txt_hoten.Text, txt_gioitinh.Text, txt_ngaysinh.Text, txt_cmnd.Text, txt_mucluong.Text, txt_hesoluong.Text,
                txt_thanhtien.Text, txt_tenphongban.Text, txt_tenchucvu.Text, txt_hesophucap.Text, txt_tienphucap.Text, txt_thamnien.Text, 
                txt_tongtien.Text, _NgayKy.ToString(), _ketquabangchu);
            frm.Show();
        }
        #endregion
    }
}
